﻿// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SnapObjects.Data
{
    /// <summary>
    ///     Provides methods to retrieve data by a dynamic query.
    /// </summary>
    /// <typeparam name="TModel">The type of a model class.</typeparam>
    public interface ISqlBuilderLoader<TModel>
    {
        /// <summary>
        ///     Retrieves data by the built SQL statement.
        /// </summary>
        /// <param name="parameters">
        ///     (Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement.
        /// </param>
        /// <returns>
        ///     Returns an <see cref="ILoadable{TModel}"/> object whose methods can be used to further obtain the result set, 
        ///     or perform data operations such as embedded queries.
        /// </returns>
        ILoadable<TModel> Load(params object[] parameters);

        /// <summary>
        ///     Asynchronously retrieves data by the built SQL statement.
        /// </summary>
        /// <param name="parameters">
        ///     (Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement.
        /// </param>
        /// <returns>
        ///     Returns a task that represents the asynchronous operation.
        /// </returns>
        Task<ILoadable<TModel>> LoadAsync(params object[] parameters);

        /// <summary>
        ///     Asynchronously retrieves data by the built SQL statement.
        /// </summary>
        /// <param name="parameters">
        ///     (Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>
        ///     Returns a task that represents the asynchronous operation.
        /// </returns>
        Task<ILoadable<TModel>> LoadAsync(object[] parameters, CancellationToken cancellationToken);

        /// <summary>
        ///     Retrieves data starting from a specified row by the built SQL statement.
        /// </summary>
        /// <param name="currentIndex">The zero-based index of the first record in the page.</param>
        /// <param name="pageSize">The count of rows in each page.</param>
        /// <param name="parameters">
        ///     (Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement.
        /// </param>
        /// <returns>
        ///     Returns an <see cref="ILoadable{TModel}"/> object whose methods can be used to further obtain the result set, 
        ///     or perform data operations such as embedded queries.
        /// </returns>
        ILoadable<TModel> LoadByPage(int currentIndex, int pageSize, params object[] parameters);

        /// <summary>
        ///     Asynchronously retrieves data starting from a specified row by the built SQL statement.
        /// </summary>
        /// <param name="currentIndex">The zero-based index of the first record in the page.</param>
        /// <param name="pageSize">The count of rows in each page.</param>
        /// <param name="parameters">
        ///     (Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement.
        /// </param>
        /// <returns>
        ///     Returns a task that represents the asynchronous operation.
        /// </returns>
        Task<ILoadable<TModel>> LoadByPageAsync(
            int currentIndex, int pageSize, params object[] parameters);

        /// <summary>
        ///     Asynchronously retrieves data starting from a specified row by the built SQL statement.
        /// </summary>
        /// <param name="currentIndex">The zero-based index of the first record in the page.</param>
        /// <param name="pageSize">The count of rows in each page.</param>
        /// <param name="parameters">
        ///     (Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement.
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>
        ///     Returns a task that represents the asynchronous operation.
        /// </returns>
        Task<ILoadable<TModel>> LoadByPageAsync(
            int currentIndex, int pageSize, object[] parameters, CancellationToken cancellationToken);
    }
}
